<template>
	<view class="dialog">
		<el-dialog :title="title" :visible.sync="dialogVisible" width="40%" :before-close="handleDialogClose">
			<!-- 用户审核 -->
			<el-form label-width="130px" v-if="title != '广告位审核' && title != '广告投放审核'">
				<el-form-item label="联系电话:" class="item" prop="linkName">
					<view>{{ item.phone }}</view>
				</el-form-item>
				<el-form-item label="公司名称:" class="item" prop="link">
					<view>{{ item.companyName }}</view>
				</el-form-item>
				<el-form-item label="审核状态:" class="item" prop="keyword">
					<view>待审核</view>
				</el-form-item>
			</el-form>
			<!-- 广告位审核 -->
			<el-form ref="form" :model="form" label-width="130px" :rules="rules" v-if="title == '广告位审核'">
				<el-form-item label="广告链接" class="item" prop="link">
					<el-input v-model="form.link" placeholder="请输入广告链接"></el-input>
				</el-form-item>
				<el-form-item label="每PV价格" class="item" prop="pvPrice">
					<el-input v-model="form.pvPrice"></el-input>
				</el-form-item>
				<el-form-item label="每UV价格" class="item" prop="uvPrice">
					<el-input v-model="form.uvPrice"></el-input>
				</el-form-item>
			</el-form>
			<!-- 投放审核 -->
			<el-form label-width="130px" v-if="title == '广告投放审核'">
				<el-form-item label="公司名称:" class="item" prop="companyName">
					<view>{{ item.companyName }}</view>
				</el-form-item>
				<el-form-item label="广告名称:" class="item" prop="bannerBtn">
					<view>{{ item.tpName }}</view>
				</el-form-item>
				<el-form-item label="每UV价格:" class="item" prop="uvPrice">
					<view>{{ item.uvPrice }}</view>
				</el-form-item>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button type="primary" @click="handleClose(1)" v-preventReClick>通过</el-button>
				<el-button type="danger" @click="handleClose(2)" v-preventReClick>拒绝</el-button>
				<el-button @click="handleClose(false)">返 回</el-button>
			</span>
		</el-dialog>
	</view>
</template>
<script>
	import {
		Request
	} from '../../model/request.js'
	import {
		Util
	} from '../../utils/util.js'
	// import {
	// 	config
	// } from "../../api/config.js";
	// import {
	// 	ServerUrl
	// } from "../../api/server_url.js";
	export default {
		props: {
			dialogVisible: '',
			second: '',
			title: {
				type: String,
				default: '审核用户'
			},
			item: {}
		},
		
		data() {
			return {
				form: {
					link: '',
					pvPrice: '',
					uvPrice: ''
				},
				rules: {
					link: [{
							required: true,
							message: '请填写广告链接',
							trigger: 'blur'
						},
						{
							pattern: /http[s]{0,1}:\/\/([\w.]+\/?)\S*/,
							message: '请输入正确的域名地址'
						}
					],
					pvPrice: [{
						required: true,
						message: '请输入pv价格',
						trigger: 'blur'
					},
					{
						pattern: /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/,
						message: '请输入正确且大于0的数'
					}],
					uvPrice: [{
						required: true,
						message: '请输入uv价格',
						trigger: 'blur'
					},
					{
						pattern: /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/,
						message: '请输入正确且大于0的数'
					}]
				}
			}
		},
		
		methods: {
			handleDialogClose(flag=false) {
				this.form = {
					link: '',
					pvPrice: '',
					uvPrice: ''
				}
				if (this.title == '广告位审核') {
					this.$refs.form.clearValidate()
				}
				this.$emit('closeDialog', flag)
			},
			
			async handleClose(e) {
				if (e == 1) { // 通过
					if (this.title == '广告位审核') {
						this.$refs.form.validate(async (valid) => {
							if (valid) {
								let res = await Request.PLACEUPDATE(this.item.id, 0, this.form.link, this.form.pvPrice, this.form.uvPrice)
								if (res.code == 200) {
									Util.showToast('操作成功')
									this.handleDialogClose(true)
								}
							}
						})
					} else if (this.title == '广告投放审核') {
						console.log('广告投放审核')
						let res = await Request.THIRDUPDATEVERITY(this.item.id, 0)
						if (res.code == 200) {
							Util.showToast('操作成功')
							this.handleDialogClose(true)
						}
					} else { // 用户审核
						let res = await Request.USERUPDATE(this.item.id, 0)
						if (res.code == 200) {
							Util.showToast('操作成功')
							this.handleDialogClose(true)
						}
					}
				} else if (e == 2) { // 拒绝
					if (this.title == '广告位审核') {
						let res = await Request.PLACEUPDATE(this.item.id, 3)
						if (res.code == 200) {
							Util.showToast('操作成功')
							this.handleDialogClose(true)
						}
					} else if (this.title == '广告投放审核') {
						console.log('广告投放审核', 1)
						let res = await Request.THIRDUPDATEVERITY(this.item.id, 1)
						if (res.code == 200) {
							Util.showToast('操作成功')
							this.handleDialogClose(true)
						}
					} else {
						let res = await Request.USERUPDATE(this.item.id, 3)
						if (res.code == 200) {
							Util.showToast('操作成功')
							this.handleDialogClose(true)
						}
					}
				} else { // 取消
					this.handleDialogClose()
				}
			}
		}
	}
</script>
<style scoped>
	.dialog {
		/* width: 100%;
	height: 100%; */
		position: absolute;
		left: 0;
		top: 0;
	}

	.el-form-item {
		position: relative;
	}

	/* .el-form-item::before {
		content: '*';
		position: absolute;
		left: 100px;
		top: 13px;
		color: red;
	} */

	/deep/ .item .el-form-item__label {
		position: relative;
		/* left: -20px; */
		/* color: red;
		border: solid 1px red;
		margin-left: 30px; */
	}

	/deep/ .item .el-form-item__label::before {
		content: ' ' !important;
	}

	.photo {
		width: 299px;
		height: 200px;
	}
	
	.el-select {
		width: 100%;
	}
</style>
